﻿using System;
using System.Collections.Generic;
using Luna.Connectors;
using Luna.Data.Test;
using NUnit.Framework;

namespace Luna.Data.Configuration
{
    [TestFixture]
    public class ConnectorTest : DataTest<IConfigurationProvider, IConnectorData>
    {
        private const string LOGIN_FORMAT = "Login";

        private const string PARAMS_FORMAT = "Params";

        private const string PASSWORD_FORMAT = "Password";

        public ConnectorTest(string contextName)
            : base(contextName)
        {
        }

        public override Action<Guid> Delete
        {
            get { return Service.DeleteConnector; }
        }

        public override Predicate<IConnectorData> DeletePredicate
        {
            get { return x => x.Params.StartsWith(TEST_PREFIX); }
        }

        public override Func<Guid, IConnectorData> Get
        {
            get { return Service.GetConnector; }
        }

        public override Func<IEnumerable<IConnectorData>> GetAll
        {
            get { return Service.GetAllConnectors; }
        }

        public override Action<IConnectorData> Save
        {
            get { return Service.SaveConnector; }
        }

        public override bool AreSame(IConnectorData P_Entity1, IConnectorData P_Entity2)
        {
            bool L_Return = true;

            L_Return &= P_Entity1.PK == P_Entity2.PK;
            L_Return &= P_Entity1.Type == P_Entity2.Type;
            L_Return &= P_Entity1.Login == P_Entity2.Login;
            L_Return &= P_Entity1.Password == P_Entity2.Password;
            L_Return &= P_Entity1.Params == P_Entity2.Params;

            return L_Return;
        }

        public override IConnectorData Create()
        {
            IConnectorData L_Entity = base.Create();
            L_Entity.PK = Guid.NewGuid();
            L_Entity.Type = GetBoolean() ? ConnectorType.Google : ConnectorType.ZohoCRM;
            L_Entity.Login = GetString(LOGIN_FORMAT);
            L_Entity.Password = GetString(PARAMS_FORMAT);
            L_Entity.Params = GetString(PASSWORD_FORMAT);
            return L_Entity;
        }
    }
}